package com.qn.sms.core.client;

import com.qn.common.core.constant.enums.ResultCodeEnum;

/**
 * 将 API 的错误码，转换为通用的错误码
 *
 * @author QN
 * @date 2022/03/03
 */
public class SmsCodeMapping {

    public static ResultCodeEnum apply(String apiCode) {
        switch (apiCode) {
            case "OK":
                return ResultCodeEnum.SUCCESS;
            case "isv.ACCOUNT_NOT_EXISTS":
            case "isv.ACCOUNT_ABNORMAL":
            case "MissingAccessKeyId":
                return ResultCodeEnum.SMS_ACCOUNT_INVALID;
            case "isp.RAM_PERMISSION_DENY":
                return ResultCodeEnum.SMS_PERMISSION_DENY;
            case "isv.INVALID_JSON_PARAM":
            case "isv.INVALID_PARAMETERS":
                return ResultCodeEnum.SMS_API_PARAM_ERROR;
            case "isv.BUSINESS_LIMIT_CONTROL":
                return ResultCodeEnum.SMS_SEND_BUSINESS_LIMIT_CONTROL;
            case "isv.DAY_LIMIT_CONTROL":
                return ResultCodeEnum.SMS_SEND_DAY_LIMIT_CONTROL;
            case "isv.SMS_CONTENT_ILLEGAL":
                return ResultCodeEnum.SMS_SEND_CONTENT_INVALID;
            case "isv.SMS_TEMPLATE_ILLEGAL":
                return ResultCodeEnum.SMS_TEMPLATE_INVALID;
            case "isv.SMS_SIGNATURE_ILLEGAL":
            case "isv.SIGN_NAME_ILLEGAL":
            case "isv.SMS_SIGN_ILLEGAL":
                return ResultCodeEnum.SMS_SIGN_INVALID;
            case "isv.AMOUNT_NOT_ENOUGH":
            case "isv.OUT_OF_SERVICE":
                return ResultCodeEnum.SMS_ACCOUNT_MONEY_NOT_ENOUGH;
            case "isv.MOBILE_NUMBER_ILLEGAL":
                return ResultCodeEnum.SMS_MOBILE_INVALID;
            case "isv.TEMPLATE_MISSING_PARAMETERS":
                return ResultCodeEnum.SMS_TEMPLATE_PARAM_ERROR;
            default:
                return ResultCodeEnum.SMS_UNKNOWN;
        }
    }
}
